<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <!-- 引入组件库 -->
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <script type="text/javascript" src="//api.map.baidu.com/api?v=2.0&ak=7OldzTQfi7oh86FaLLal2kX8k3kGSMMa"></script>
    <style>
        .avatar-uploader .el-upload {
            border: 1px dashed #d9d9d9;
            border-radius: 6px;
            cursor: pointer;
            position: relative;
            overflow: hidden;
        }
        .avatar-uploader .el-upload:hover {
            border-color: #409EFF;
        }
        .avatar-uploader-icon {
            font-size: 28px;
            color: #8c939d;
            width: 178px;
            height: 178px;
            line-height: 178px;
            text-align: center;
        }
        .avatar {
            width: 178px;
            height: 178px;
            display: block;
        }
        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 1 1 0%;
        }
        .datatable td, .datatable th {
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }

        #allmap{
            height: 450px;
            width: 100%;
            overflow: hidden;
            font-family: "微软雅黑";
            border:1px solid green;
        }

        /*百度地图搜索框定位*/
        .tangram-suggestion-main {
            z-index: 999999;
        }
        /*设置弹出框样式*/
        .el-dialog__body {
            padding: 0px 20px;
            color: #606266;
            font-size: 14px;
        }
        /**/
        .el-input--suffix .el-input__inner {
            width: 450px;
        }
    </style>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>首页<small>公司分布图</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>公司分布图</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <template>
            <el-tabs v-model="activeName"  @tab-click="handleClick">
                <el-tab-pane label="分布图" name="first">
                    <iframe name="right" class="el-main" src="../bmaps/map.html" width="100%" height="580px" frameborder="0"></iframe>
                </el-tab-pane>

                <el-tab-pane label="详细信息" name="second">
                    <div class="filter-container">
                        <el-input placeholder="公司地址" v-model="pagination.queryString" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                        <el-button @click="findPage()" class="dalfBut">查询</el-button>
                        <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
                    </div>
                    <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                        <el-table-column type="index" align="center" label="序号"></el-table-column>
                        <el-table-column prop="address" label="公司地址"  align="center"></el-table-column>

                        <el-table-column prop="longitude" label="所在经度" align="center"></el-table-column>
                        <el-table-column prop="latitude" label="所在纬度" align="center"></el-table-column>
                        <el-table-column label="操作" align="center">
                            <template slot-scope="scope">
                                <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
                                <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <div class="pagination-container">
                        <el-pagination
                                class="pagiantion"
                                @current-change="handleCurrentChange"
                                :current-page="pagination.currentPage"
                                :page-size="pagination.pageSize"
                                layout="total, prev, pager, next, jumper"
                                :total="pagination.total">
                        </el-pagination>
                    </div>
                    <!-- 编辑标签弹层 -->
                    <div class="edit-form">
                        <el-dialog title="新增地址" :visible.sync="dialogFormVisible4Edit">
                            体检机构名：<input type="text" id="name_edit" name="address_name"  v-model="formData.name" class="input_style">
                            联系电话：<input type="text" id="tel_edit" name="address_tel"  v-model="formData.tel" class="input_style">
                            <br>
                            <br>

                                <el-upload
                                        class="avatar-uploader"
                                        action="/setmeal/upload.do"
                                        :auto-upload="autoUpload"
                                        name="imgFile"
                                        :show-file-list="false"
                                        :on-success="handleAvatarSuccess"
                                        :before-upload="beforeAvatarUpload">
                                    <img v-if="imageUrl" :src="imageUrl" class="avatar">
                                    <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                                </el-upload>
                            <br>
                            <br>

                            经度：<input type="text" id="latitude_edit" name="address_latitude"  v-model="formData.latitude"  class="input_style">

                            纬度：<input type="text" id="longitude_edit" name="address_longitude"  v-model="formData.longitude"  class="input_style">
                            <br>
                            <br>
                            详细地址：<input type="text" id="address_edit" name="address_address"  v-model="formData.address" class="input_style">
                            <el-button @click="setAddress()">设置定位</el-button>
                            <br>
                            <br>
                            <div id="allmap_edit"></div>
                            <div id="searchResultPanel_edit" style="border:1px solid #C0C0C0;width:150px;height:auto; display:none;"></div>
                            <div slot="footer" class="dialog-footer">
                                <el-button @click="dialogFormVisible = false">取消</el-button>
                                <el-button type="primary" @click="handleAdd()">确定</el-button>
                            </div>
                        </el-dialog>
                    </div>
                    <!-- 新增标签弹层 -->
                    <div class="add-form">
                        <el-dialog title="新增地址" :visible.sync="dialogFormVisible">
                            体检机构名：<input type="text" id="name" name="address_name"  v-model="formData.name" class="input_style">
                            联系电话：<input type="text" id="tel" name="address_tel"  v-model="formData.tel" class="input_style">
                            <br>
                            <br>

                            <el-upload
                                    class="avatar-uploader"
                                    action="/setmeal/upload.do"
                                    :auto-upload="autoUpload"
                                    name="imgFile"
                                    :show-file-list="false"
                                    :on-success="handleAvatarSuccess"
                                    :before-upload="beforeAvatarUpload">
                                <img v-if="imageUrl" :src="imageUrl" class="avatar">
                                <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                            </el-upload>
                            <br>
                            <br>

                            经度：<input type="text" id="latitude" name="address_latitude"  v-model="formData.latitude"  class="input_style">

                            纬度：<input type="text" id="longitude" name="address_longitude"  v-model="formData.longitude"  class="input_style">
                            <br>
                            <br>
                            详细地址：<input type="text" id="address" name="address_address"  v-model="formData.address" class="input_style">
                            <el-button @click="setAddress()">设置定位</el-button>
                            <br>
                            <br>
                            <div id="allmap"></div>
                            <div id="searchResultPanel" style="border:1px solid #C0C0C0;width:150px;height:auto; display:none;"></div>
                            <div slot="footer" class="dialog-footer">
                                <el-button @click="dialogFormVisible = false">取消</el-button>
                                <el-button type="primary" @click="handleAdd()">确定</el-button>
                            </div>
                        </el-dialog>
                    </div>
                </el-tab-pane>
            </el-tabs>
        </template>
    </div>
</div>
</body>

<script>
    var vue = new Vue({
        el: '#app',
        data:{
            autoUpload:true,//自动上传
            imageUrl:null,//模型数据，用于上传图片完成后图片预览
            activeName:'first',//添加/编辑窗口Tab标签名称
            pagination: {//分页相关属性
                currentPage: 1,
                pageSize:10,
                total:100,
                queryString:null,
            },
            dataList: [],//列表数据
            formData: {},//表单数据
            tableData:[],//新增和编辑表单中对应的检查项列表数据
            dialogFormVisible: false,//控制添加窗口显示/隐藏
            dialogFormVisible4Edit:false,//控制编辑窗口显示/隐藏
            address_detail:'', //详细地址
            userlocation: {longitude: "", latitude: ""}
        },
        mounted () {

        },
        created() {
//调用分页查询方法完成分页查询
            this.findPage();
        },
        methods: {
            setAddress(){
                var map = new BMap.Map("allmap");
                var point = new BMap.Point(116.331398,39.897445);
                map.centerAndZoom(point,12);

                var geolocation = new BMap.Geolocation();
                geolocation.getCurrentPosition(function(r){
                    if(this.getStatus() == BMAP_STATUS_SUCCESS){
                        var mk = new BMap.Marker(r.point);
                        map.addOverlay(mk);
                        map.panTo(r.point);
                        var local = new BMap.LocalSearch(map, {
                            renderOptions:{map: map}
                        });
                        local.search("体检");
                        // alert('您的位置：'+r.point.lng+','+r.point.lat);
                    }
                    else {
                        alert('failed'+this.getStatus());
                    }
                },{enableHighAccuracy: true})
            },
            //文件上传成功后的钩子，response为服务端返回的值，file为当前上传的文件封装成的js对象
            handleAvatarSuccess(response, file) {
                this.$message({
                    type:response.flag?"success":"error",
                    message:response.message
                });
                if(response.flag){
                    //预览刚刚上传的文件
                    this.imageUrl = "http://qgvu6wvef.hd-bkt.clouddn.com/"+response.data;
                    this.formData.img = response.data;//将文件名称赋值给模型数据，用于表单提交
                }
            },
            //上传图片之前执行
            beforeAvatarUpload(file) {
                const isJPG = file.type === 'image/jpeg';
                const isLt2M = file.size / 1024 / 1024 < 2;
                if (!isJPG) {
                    this.$message.error('上传套餐图片只能是 JPG 格式!');
                }
                if (!isLt2M) {
                    this.$message.error('上传套餐图片大小不能超过 2MB!');
                }
                return isJPG && isLt2M;
            },
            //分页查询
            findPage() {
                var param = {
                        currentPage:this.pagination.currentPage,
                        pageSize:this.pagination.pageSize,
                        queryString:this.pagination.queryString
                };
                //发送ajax请求，进行分页查询
                axios.post("/address/findPage.do",param).then((res) => {
                        this.pagination.total = res.data.total;
                        this.dataList = res.data.rows;
            });
            },
            // 重置表单
            resetForm() {
                this.address_detail=null;
                this.formData = {};
            },
            // 弹出添加窗口
            handleCreate() {
                this.resetForm();
                //将添加窗口展示出来
                this.dialogFormVisible = true;
            },
            // 弹出编辑窗口
            handleUpdate(row) {
                this.resetForm();
                //将添加窗口展示出来
                this.dialogFormVisible4Edit = true;
                //回显数据
                axios.get("/address/findById.do?id=" + row.id).then((res) => {
                    if(res.data.flag){
                        this.formData = res.data.data;//为模型数据赋值，基于VUE数据绑定进行回显
                    }else{
                        this.$message.error(res.data.message);
                    }
                });
            },
            //切换页码
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;//指定最新的页码
                this.findPage();
            },
            // 删除
            handleDelete(row) {
                //弹出确认框
                this.$confirm('你确定要删除当前数据吗？','提示',{
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    //发送ajax请求，将id提交到Controller
                    axios.get("/address/delete.do?id=" + row.id).then((res) => {
                        if(res.data.flag){
                            this.$message({
                                type:'success',
                                message:res.data.message
                            });
                            this.findPage();
                        }else{
                            //执行失败
                            this.$message.error(res.data.message);
                        }
                    });
                }).catch(() => {
                    this.$message("已取消");
                });
            },
            handleAdd(){
                axios.post("/address/add.do",this.formData).then((res)=>{
                    //关闭新增窗口
                    this.dialogFormVisible = false;
                    if (res.data.flag){
                        this.$message({
                            type:'success',
                            message:res.data.message
                        });
                        this.findPage();
                    }else{
                        this.$message.error(res.data.message);
                    }
                })
            },
            handleClick(tab, event) {
               
            }
        }
    });
</script>
</html>